#include "Data.h"
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <iostream>

int main() {
  using namespace boost::interprocess;

  shared_memory_object::remove("MySharedMemory");
  managed_shared_memory segment(create_only, "MySharedMemory", 65536);

  typedef allocator<int, managed_shared_memory::segment_manager> ShmemAllocator;
  typedef vector<int, ShmemAllocator> MyVector;

  ShmemAllocator alloc_inst(segment.get_segment_manager());
  // MyVector* my_vector = segment.construct<MyVector>("MyVector")(alloc_inst);
  MyVector *my_vector =
      segment.find_or_construct<MyVector>("MyVector")(alloc_inst);

  for (int i = 0; i < 10; ++i)
    my_vector->push_back(i * 10);

//   CharAllocator alloc_inst1(segment.get_segment_manager());
  SharedString name("Alice", alloc_inst);

  segment.construct<std::pair<float, double>>("MyPair")(3.14f, 6.28);
  segment.construct<Person>("MyPerson")(22, 1.72f, name);

  std::cout << "Writer done.\n";
  return 0;
}
